import Vue from 'vue'
import VueRouter from 'vue-router'

// 导入动态路由
// import systemRoute from './modules/systemRoute'
// import contentRoute from './modules/contentRoute'
// import advRoute from './modules/advRoute'
// import userRoute from './modules/userRoute'

Vue.use(VueRouter)

// 动态路由配置
// const asyncRoutes = [systemRoute, contentRoute, advRoute, userRoute]

// 静态路由配置
export const staticRoutes = [
  {
    path: '/',
    component: () => import('@/views/layout'),
    // 重定向
    redirect: '/dashboard',
    meta: { title: 'dashboard' },
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard'),
        meta: { title: 'dashboard' }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
  // {
  //   path: '*',
  //   redirect: '/404',
  //   hidden: true
  // }
]

// 创建路由的方法
const createRouter = () =>
  new VueRouter({
    scrollBehavior: () => ({ y: 0 }),
    // 静态路由+动态路由合并在一起
    // routes: [...staticRoutes, ...asyncRoutes]
    // 只有静态路由
    routes: [...staticRoutes]
  })
// 调用，得到一个路由实例对象
const router = createRouter()

// 重置路由的方法
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
